package in.iqing.model.sp;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by neavo on 2014/6/28.
 */

public class SettingSP {

    private SharedPreferences slnovelsp;
    private static SettingSP singleton;

    public static final int TEXT_SIZE_SMALL = 1;
    public static final int TEXT_SIZE_NORMAL = 2;
    public static final int TEXT_SIZE_LARGE = 3;
    public static final int TEXT_SIZE_EXLARGE = 4;

    private SettingSP(Context ctx) {
        this.slnovelsp = ctx.getSharedPreferences("settingsp", Context.MODE_PRIVATE);
    }

    public static synchronized SettingSP getSingleton(Context ctx) {
        if (singleton == null) {
            singleton = new SettingSP(ctx);
        }

        return singleton;
    }

    public void clear() {
        slnovelsp.edit().clear().apply();
    }

    public int getSize() {
        return slnovelsp.getInt("size", TEXT_SIZE_NORMAL);
    }

    public void setSize(int value) {
        slnovelsp.edit().putInt("size", value).apply();
    }

    public int getSpace() {
        return slnovelsp.getInt("space", 4);
    }

    public void setSpace(int value) {
        slnovelsp.edit().putInt("space", value).apply();
    }

    public boolean getNightMode() {
        return slnovelsp.getBoolean("nightmode", false);
    }

    public void setNightMode(boolean value) {
        slnovelsp.edit().putBoolean("nightmode", value).apply();
    }

    public boolean getAlwaysOn() {
        return slnovelsp.getBoolean("alwayson", false);
    }

    public void setAlwaysOn(boolean value) {
        slnovelsp.edit().putBoolean("alwayson", value).apply();
    }

    public boolean getTraditional() {
        return slnovelsp.getBoolean("traditional", false);
    }

    public void setTraditional(boolean value) {
        slnovelsp.edit().putBoolean("traditional", value).apply();
    }

    public void setUseSystemBrightness(boolean value) {
        slnovelsp.edit().putBoolean("use_system_brightness", value).apply();
    }

    public boolean isUseSystemBrightness() {
        return slnovelsp.getBoolean("use_system_brightness", true);
    }

    public void setBrightness(float brightness) {
        slnovelsp.edit().putFloat("brightness", brightness).apply();
    }

    public float getBrightness() {
        return slnovelsp.getFloat("brightness", 0);
    }
}
